<?php


namespace app\service;


use app\model\StepCategoryModel;
use app\model\StepModel;
use app\tool\SingletonTrait;

class StepCategoryService
{
    use SingletonTrait;

    function __construct()
    {

    }

    /**
     * 获取环节上下游关系
     * @param array $stepCategoryIdList
     * @return array
     */
    public function getStepCategoryUpstreamDownstreamRelation(array $stepCategoryIdList): array
    {
        $res = [];
        $serviceName = "teamones-saas";
        $endPoint = "step_category/upstream_relation";
        $data = json_encode([
            'param' => [
                'filter' => [
                    'id' => ['-in', $stepCategoryIdList],
                ]
            ]
        ]);
        $res = teamones_request($serviceName, $endPoint, $data);
        return array_column($res['data'], null, 'id');
    }

    /**
     * 获取显示工序分类组
     * @return array
     * @throws \think\Exception
     */
    public function getShowStepCategoryGroup($params)
    {
        $res = OptionsService::getInstance()->getProjectShowStepCategoryListConfig($params['project_id']);
        return $res;
    }

    /**
     * 获取分类下面的子分类列表
     */
    public function getStepCategoryFollowList($categoryId)
    {
        return StepCategoryModel::where('parent_id', $categoryId)->cache("step_category_follow_list_{$categoryId}")->select();
    }

    /**
     * 获取工序分类下面的工序列表
     */
    public function getStepCategoryFollowStepList($categoryId)
    {
        return StepModel::where('step_category_id', $categoryId)->cache("step_category_follow_step_list_{$categoryId}")->select();
    }
}